let mapleader = " "
let maplocalleader = " "

" Load local .vimrc files
set exrc
set secure

packadd chezmoi.vim

{{ if eq .os "windows" -}}
set nocompatible " Get out of vi compatible mode

{{ else -}}
{{ end -}}

if !exists("*ReloadConfigs")
  function ReloadConfigs()
{{- if eq .rtp "~/.vim" }}
    :source ~/.vim/vimrc
    if has('gui_running')
      :source ~/.vim/gvimrc
    endif
{{- else if eq .rtp "~/.config/nvim" }}
    :source ~/.config/nvim/init.vim
{{- end }}
  endfunction
  command! RC call ReloadConfigs()
endif

" Auto source $MYVIMRC after saving
augroup auto_source_vimrc
  autocmd!
  autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END

{{ if eq .vim_flag "good" -}}
let g:config_files = [
      \ 'misc.vim',
      \ 'cursor.vim',
      \ 'spell.vim',
      \ 'colour.vim',
      \ 'clipboard.vim',
      \ 'buffer.vim',
      \ 'window.vim',
{{-   if ne .os "linux" }}
      \ 'python.vim',
{{-   end }}
      \ 'plug.vim',
      \ 'gruvbox-material.vim',
      \ 'edge.vim',
      \ 'theme.vim',
      \ ]
" Strict loading order: 'plug.vim' -> 'gruvbox-material/edge.vim' -> 'theme.vim'

{{ else -}}
let g:tex_comment_nospell = 1 " For VimTeX use g:vimtex_syntax_nospell_comments

let g:config_files = [
      \ 'misc.vim',
      \ 'cursor.vim',
      \ 'spell.vim',
      \ 'colour.vim',
      \ 'clipboard.vim',
      \ 'buffer.vim',
      \ 'window.vim',
{{-   if ne .os "linux" }}
      \ 'python.vim',
{{-   end }}
      \ ]

{{ end -}}

for s:fname in g:config_files
{{ list "  execute printf('source " .rtp "/core/%s', s:fname)" | join "" }}
endfor
